package com.example.myapplication2;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class SpinnerActivity extends AppCompatActivity {

/*private String selectColor;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_spinner);
        initView();
    }
    private  void initView(){
        Spinner colorSpiner = findViewById(R.id.string001);
        List<String> list = new ArrayList<String>();
        list.add("选择颜色");
        list.add("红色|Red");
        list.add("黄色|Yellow");
        list.add("绿色|Green");
        list.add("蓝色|Blue");
        list.add("橙色|Orange");
        //参数2：下拉列表条目
        //参数3：动态数据
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_dropdown_item,list);
        //给下拉列表设置列表条目布局
        //adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        colorSpiner.setAdapter(adapter);


        //参数2：strings.xml中的数据
        //参数3：Spinner头部布局，当前使用系统布局android.R.layout.simple_spinner_dropdown_item
      *//*  ArrayAdapter adapter = ArrayAdapter.createFromResource(
                this,R.array.Str_color,
                android.R.layout.simple_spinner_dropdown_item);*//*
        //给下拉列表设置列表条目布局
        *//*adapter.setDropDownViewResource(
                android.R.layout.simple_spinner_dropdown_item
        );*//*
        //colorSpiner.setAdapter(adapter);
        //设置是否显示控件，对应属性为android：visible
        colorSpiner.setVisibility(View.VISIBLE);

        colorSpiner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {

               if(position!=0 || !TextUtils.isEmpty(selectColor)){
                   *//*Toast.makeText(SpinnerActivity.this,"选中了："+
                                   getResources().getStringArray(R.array.Str_color)[position],
                           Toast.LENGTH_SHORT).show();*//*
                   Toast.makeText(SpinnerActivity.this,"选中了："+
                                   list.get(position),
                           Toast.LENGTH_SHORT).show();
               }


            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });

    }*/
}